const db = require('../db/index');
const DataType = require('sequelize');
const Members = require('./Members');
/**es6继承 */
class User extends DataType.Model {}
User.init(
    {
        id: {
            type: DataType.INTEGER,
            allowNull: false,
            autoIncrement: true,
            primaryKey: true
        },
        nickName: {
            type: DataType.STRING,
            comment: '名称',
            allowNull: false
        },
        avatarUrl: {
            type: DataType.STRING,
            comment: '头像',
            allowNull: false
        },
        openId: {
            type: DataType.STRING,
            comment: 'openId',
            allowNull: false
        },
        sessionKey: {
            type: DataType.STRING,
            comment: 'openId',
            allowNull: false
        },
        phone: {
            type: DataType.STRING,
            comment: '手机号'
        },
        parentId: {
            type: DataType.INTEGER,
            comment: '上级ID',
            defaultValue: 0,
            allowNull: false
        },
        memberId: {
            type: DataType.INTEGER,
            comment: '会员卡ID',
            defaultValue: 0
        },
        cardTimeId: {
            type: DataType.INTEGER,
            comment: '次卡ID'
        },
        leftDay: {
            type: DataType.INTEGER,
            comment: '剩余多少天',
            defaultValue: 0,
            allowNull: false
        },
        limit: {
            type: DataType.INTEGER,
            comment: '剩余次数',
            defaultValue: 0,
            allowNull: false
        },
        reward: {
            type: DataType.INTEGER,
            comment: '领取奖励次数',
            defaultValue: 0,
            allowNull: false
        },
        buyMemberTime: {
            type: DataType.INTEGER,
            comment: 'VIP购买时间'
        },
        member: {
            type: DataType.DECIMAL(10, 2),
            comment: 'VIP购买金额'
        },
        cardTime: {
            type: DataType.DECIMAL(10, 2),
            comment: '次卡购买金额'
        },
        endMemberTime: {
            type: DataType.INTEGER,
            comment: 'VIP结束时间'
        },
        buyCardTime: {
            type: DataType.INTEGER,
            comment: '次卡购买时间'
        },
        endCardTime: {
            type: DataType.INTEGER,
            comment: '次卡结束时间'
        },
        status: {
            type: DataType.BOOLEAN,
            comment: '0冻结 1正常',
            defaultValue: 1,
            allowNull: false
        },
        isMember: {
            type: DataType.BOOLEAN,
            comment: '是否会员',
            defaultValue: 0
        },
        isTimeCard: {
            type: DataType.BOOLEAN,
            comment: '是否次卡',
            defaultValue: 0
        }
    },
    {
        tableName: 'users',
        modelName: 'users',
        sequelize: db
    }
);
// User.sync({ force: true });
User.belongsTo(Members['default'], {
    as: 'membersInfo',
    foreignKey: 'memberId'
});
exports['default'] = User;
